package com.wwwarehouse.usercenter.fragment.permissiondistribute;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.bean.authoritydistribute.DistributeResultBean;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;

import de.greenrobot.event.EventBus;

/**
 * 分配完成->全部分配失败
 * Created by ShineF on 2017/9/25 0025.
 */

public class PermissionDistributeAllErrorFragment extends BaseFragment implements View.OnClickListener {

    private Button mBtnDetails = null;
    private Button mBtnContinue = null;
    private Button mBtnCardDesk = null;
    private DistributeResultBean bean = null;
    private String mBusinessUnitId;
    private Bundle mBundle;
    private String mType;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_all_distribute_error, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mBtnDetails = $(R.id.btn_distribute_details);
        mBtnContinue = $(R.id.btn_continue_distribute);
        mBtnCardDesk = $(R.id.btn_goto_desk);
        ((BaseCardDeskActivity) mActivity).hideBackBt();
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof PermissionDistributeAllErrorFragment) {
            mActivity.setTitle(R.string.receiver_permission);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ((BaseCardDeskActivity) mActivity).showBackBt();
    }

    @Override
    public void requestDatas() {
        mBundle = getArguments();
        if (null == mBundle) {
            return;
        }
        bean = mBundle.getParcelable("resultBean");
        mType = mBundle.getString("type");
        mBusinessUnitId = sp.getValue(UserCenterConstant.SAVE_BUSINESSUNITID);
        mBtnDetails.setOnClickListener(this);
        mBtnContinue.setOnClickListener(this);
        mBtnCardDesk.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.btn_distribute_details) {
            DistributePermissionErrorPagerFragment fragment = new DistributePermissionErrorPagerFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("type", 0);
            bundle.putParcelable("resultBean", bean);
            fragment.setArguments(bundle);
            pushFragment(fragment);
        } else if (view.getId() == R.id.btn_continue_distribute) {
            Bundle bundle = new Bundle();
            switch (mType) {
                case "distribution":
                    CardDeskFunctionResponseBean.TaskBean bean = new CardDeskFunctionResponseBean.TaskBean();
                    bean.setBusinessId(mBusinessUnitId);
                    bundle.putSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS, bean);
                    break;
                case "CheckDownClassFragment":
                    bundle.putString("personName", mBundle.getString("personName"));
                    bundle.putString("userId", mBundle.getString("userId"));
                    bundle.putString("buId", mBundle.getString("buId"));
                    bundle.putString("CheckDownClassFragment", "CheckDownClassFragment");
                    break;
            }
            AuthorityDistributePagerFragment fragment = new AuthorityDistributePagerFragment();
            fragment.setArguments(bundle);
            EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
            pushFragment(fragment);
        } else if (view.getId() == R.id.btn_goto_desk) {
            EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
        }
    }
}
